from django.core.management.base import BaseCommand
from preheat.scheduler import start_scheduler

class Command(BaseCommand):
    help = '启动自动任务调度器，执行所有激活的自动预热任务'
    
    def handle(self, *args, **options):
        self.stdout.write(self.style.SUCCESS('正在启动自动任务调度器...'))
        try:
            # 启动调度器
            start_scheduler()
        except KeyboardInterrupt:
            self.stdout.write(self.style.SUCCESS('\n调度器已被用户中断'))
        except Exception as e:
            self.stdout.write(self.style.ERROR(f'调度器启动失败: {str(e)}'))
            import traceback
            traceback.print_exc()